{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4.1. Evaluating the time taken by a command in IPython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 100000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "21.6 ms ± 343 µs per loop (mean ± std. dev. of 7 runs,\n",
      "    10 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit sum([1. / i**2 for i in range(1, n)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22 ms ± 522 µs per loop (mean ± std. dev. of 7 runs,\n",
      "    10 loops each)\n"
     ]
    }
   ],
   "source": [
    "%%timeit s = 0.\n",
    "for i in range(1, n):\n",
    "    s += 1. / i**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "160 µs ± 959 ns per loop (mean ± std. dev. of 7 runs,\n",
      "    10000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit np.sum(1. / np.arange(1., n) ** 2)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
